import * as redisStore from 'cache-manager-redis-store'
import { RedisClientOptions } from 'redis'
import { ConfigService } from '@nestjs/config'
import { Module, CacheModule } from '@nestjs/common'
import { RedisService } from './redis.service'

@Module({
  imports: [
    CacheModule.registerAsync<RedisClientOptions>({
      inject: [ConfigService],
      useFactory(configService: ConfigService<ENV_CONFIG>) {
        return {
          store: redisStore,
          database: 0,
          ttl: 500,
          socket: {
            host: configService.get('JWT.JWT_EXPIRES', { infer: true }),
            port: configService.get('REDIS.REDIS_PORT', { infer: true })
          }
        }
      }
    })
  ],
  providers: [RedisService],
  exports: [RedisService]
})
export class RedisModule {}
